package com.oa.tools.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.oa.tools.jobs.DynamicJob;
import com.oa.tools.utils.FileUtil;
import com.oa.tools.utils.ObjectUtil;
import com.oa.tools.utils.SysConfig;

@RestController
@RequestMapping(path = "lbpm")
public class OAFlowCallBackController {

	public static final Logger logger = LoggerFactory.getLogger(DynamicJob.class);
	
	@RequestMapping( value= "callback") 
	public Map<String,Object> callback(@RequestBody String jsonParam) throws Exception {
		
//		@RequestBody 
		Map<String,Object> param = ObjectUtil.json2Map(jsonParam);
		logger.info("callback received oa flow notice callback message:"+param.toString());
		FileUtil.writeTxt2File(param.toString(), SysConfig.getOutPath());
		
		
		Map<String,Object> response = new HashMap<>();
		response.put("msg", "success");
		return response;
	}
	
	@RequestMapping({ "callbacktest" })
	public Map<String,Object> callbacktest(@RequestBody Map<String,Object> param) throws Exception {
		
		logger.info("callbacktest received oa flow notice callback message:"+param.toString());
		FileUtil.writeTxt2File(param.toString(), SysConfig.getOutPath());
		
		
		Map<String,Object> response = new HashMap<>();
		response.put("msg", "success");
		return response;
	}
}